from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from common.Utils import oj_driver


# 进行整体的搜索界面

class Index:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://111.230.81.226:8080/index.html"
        self.driver = oj_driver.driver

    # 正确登录后的场景
    def LoginSuccess(self):
        # 如果是正确登录，那么此时界面上应该有对应的内容信息
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div.navbar > a:nth-child(1)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div.navbar > a:nth-child(2)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div.content > a")
        oj_driver.getScreenShot()
        # 之后就可以进入到OJ列表页面了
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div.content > a").click()


class IndexNoLogin:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://111.230.81.226:8081/index.html"
        self.driver = oj_driver.driver
        self.driver.get(self.url)

    # 异常登录后的场景
    def NoLoginToIndex(self):
        # 如果是异常登录，应该有一个提示框信息，内容是请先登录
        WebDriverWait(self.driver, 5).until(EC.alert_is_present())
        alert = self.driver.switch_to.alert
        alertval = alert.text
        assert (alertval == "请先登录")
        # 点击确认
        alert.accept()
        oj_driver.getScreenShot()
